package com.zz.controller;

import com.zz.common.Log;
import com.zz.common.R;
import com.zz.entity.Activity;
import com.zz.entity.Club;
import com.zz.service.ActivityService;
import com.zz.service.ClubService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Nullable;
import javax.validation.Valid;
import java.util.List;

/**
 * 学校管理员操作
 * @author 朱彦燕
 */
@RestController
@Slf4j
@RequestMapping("/admin")
@CrossOrigin
@Validated
public class AdminController {

    @Autowired
    private ActivityService activityService;

    @Autowired
    private ClubService clubService;


    /**
     * 展示所有社团申请举办活动的信息
     * 朱彦燕,测试通过
    * */
    @RequiresRoles("admin")
    @GetMapping("/show")
    @Log(title = "学校管理员：展示所有社团申请举办活动的信息")
    @Transactional
    public R<List<Activity>> showApplication(@Nullable @RequestParam String activityName){
        log.info("开始执行showApplication方法！");
        return activityService.showApplication(activityName);
    }

    /**
    * 同意活动申请
    * 朱彦燕
    * 测试成功
    * */
    @RequiresRoles("admin")
    @PutMapping("/agree")
    @Transactional
    @Log(title = "学校管理员：同意活动举办申请", dataLocationType = "body")
    public R<String> agree(@RequestBody @Validated(Delete.class) Activity activity){
        return activityService.agree(activity);
    }

    /**
    *拒绝活动申请
    *朱彦燕
    *测试成功
    */
    @RequiresRoles("admin")
    @PutMapping("/decline")
    @Transactional
    @Log(title = "学校管理员：拒绝活动举办申请", dataLocationType = "body")
    public R<String> decline(@RequestBody @Validated(Delete.class) Activity activity){
        return activityService.decline(activity);
    }

    /**
    * 注册社团
    * */
    @RequiresRoles("admin")
    @PostMapping("/registerClub")
    @Transactional
    @Log(title = "学校管理员：注册社团", dataLocationType = "body")
    public R<String> registerClub(@RequestBody @Valid Club club){
        return clubService.registerClub(club);
    }
}
